<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<base href="<%=basePath%>">

		<title>转载规则检测</title>

		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<meta http-equiv="expires" content="0">
		<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
		<meta http-equiv="description" content="This is my page">
		<!--
			<link rel="stylesheet" type="text/css" href="styles.css">
		-->
		<!-- 表头 -->
		<jsp:include page="/pages/loginUser.jsp" flush="true"/>
		
		<!-- jquery -->
		<jsp:include page="/pages/basic/easyui_loder.jsp" flush="true"/>
		
		<script type="text/javascript" src="js_lib/lucene/jsUtil.js"></script>
		
		<style type="text/css">
			.middleContent{
				text-align: left;
				margin-right: auto;
				margin-left: auto;
				width: 1024px;
			}
		</style>
		<script type="text/javascript">
			
			/**
			 * 检验url 正则
			 */
			var checkUrlReg = function(){
				
				var urlReg = $("#urlRegDiv").val();
				
				var matchUrl = $("#matchDiv").val();
				
				var patt1 = new RegExp(urlReg);
				var flag = patt1.test(matchUrl);
				
				if(flag){//匹配
					alert(" √ 正则表达式与 url 匹配！");
				}else{
					alert(" × 不匹配");
				}
			}
			
			/**
			 * 提取发稿日期
			 */
			var catchPublishDay = function(){
				maskOnLoad("正则提取发稿日期，请稍候...");
				
				var publishUrl = $("#publishUrl").val();
				var publishDayRule = $("#publishDayRule").val();
				
				var params = {
					publishUrl: publishUrl,
					publishDayRule: publishDayRule
				};
    			$.ajax({
					type : "POST",
					dataType : "text",
					url: "publish_catchPublishDay",
					data: params,
					success : function(dataText){
						$("#publishDayValue").html(dataText);
						closeMask();
					},
					error : function(XMLHttpRequest, textStatus,errorThrown){
						closeMask();
						alert("网络连接失败");
					}
				});
				
			}
			
			/**
			 * 提取转载网站名称
			 */
			var catchPublishName = function(){
				maskOnLoad("正则提取转载网站名称，请稍候...");
				
				var publishUrl = $("#publishUrl").val();
				var publishNameRule = $("#publishNameRule").val();
				
				var params = {
					publishUrl: publishUrl,
					publishNameRule: publishNameRule
				};
    			$.ajax({
					type : "POST",
					dataType : "text",
					url: "publish_catchPublishName",
					data: params,
					success : function(dataText){
						$("#publishNameValue").html(dataText);
						$("#firstPublish").val(dataText);
						closeMask();
					},
					error : function(XMLHttpRequest, textStatus,errorThrown){
						closeMask();
						alert("网络连接失败");
					}
				});
			}
			
			/**
			 * 正则二次匹配转载名称
			 */
			var getRegexMatch = function(){
				maskOnLoad("正在正则匹配，请稍候...");
				
				var firstPublish = $("#firstPublish").val();
				var regex = $("#regex").val();
				
				var params = {
					firstPublish: firstPublish,
					regex: regex
				};
    			$.ajax({
					type : "POST",
					dataType : "text",
					url: "publish_getRegexMatch",
					data: params,
					success : function(dataText){
						$("#matchFirstPublish").html(dataText);
						closeMask();
					},
					error : function(XMLHttpRequest, textStatus,errorThrown){
						closeMask();
						alert("error...");
					}
				});
				
			}
			
			
		</script>
		

	</head>

	<body style="text-align: center; margin: 0;">
		<div class="middleContent">
			<hr/>
			<h1>url 爬取规则校验</h1>
			<table border="0">
				<tr>
					<td>请输入url正则表达式:</td>
					<td>
						<input type="text" style="width: 650px; height: 30px;" id="urlRegDiv" value="^https?://.*sina.com.cn.*/\d{4}-?\d{2}-?\d{2}/.*\.s?html?$">
					</td>
				</tr>
				<tr>
					<td>请输入要匹配的url:</td>
					<td>
						<input type="text" style="width: 650px; height: 30px;" id="matchDiv" value="http://news.sina.com.cn/c/2015-04-02/113231674608.shtml">
					</td>
				</tr>
				<tr>
					<td colspan="2" align="right">
						<input type="button" value="校验url" onclick="checkUrlReg()">
					</td>
				</tr>
			</table>
			<br/>
			<hr/>
			
			<h1>发稿日期与转载名称规则校验</h1>
			<table border="1">
				<tr>
					<td>请输入要检测的url地址:</td>
					<td colspan="3">
						<input type="text" style="width: 650px; height: 30px;" id="publishUrl" value="http://ah.anhuinews.com/system/2014/03/10/006343459.shtml" />
					</td>
				</tr>
				<tr>
					<td>请输入发稿日期规则:</td>
					<td width="250px;">
						<input type="text" style="width: 245px;" id="publishDayRule" value="div[class=content_w sjjg] div:eq(0) div:eq(0)" />
					</td>
					<td width="120px;">
						<input type="button" value="提取发稿日期" onclick="catchPublishDay()" />
					</td>
					<td>
						<div id="publishDayValue" style="color: red;"></div>
					</td>
				</tr>
				<tr>
					<td>请输入转载名称规则:</td>
					<td width="250px;">
						<input type="text" style="width: 245px;" id="publishNameRule" value="div[class=content_w sjjg] div:eq(0) div:eq(0)">
					</td>
					<td width="120px;">
						<input type="button" value="提取转载名称" onclick="catchPublishName()">
					</td>
					<td>
						<div id="publishNameValue" style="color: red;"></div>
					</td>
				</tr>
				
				<tr>
					<th colspan="4" style="background-color: #ACA899;">正则二次匹配转载名称</th>
				</tr>
				<tr>
					<td>请输入转载名称:</td>
					<td>
						<input type="text" style="width: 245px;" id="firstPublish" name="firstPublish">
					</td>
					<td rowspan="2">
						<input type="button" value="正则过滤" onclick="getRegexMatch()">
					</td>
					<td rowspan="2">
						<div id="matchFirstPublish" style="color: red;"></div>
					</td>
				</tr>
				<tr>
					<td>请输入正则表达式:</td>
					<td>
						<input type="text" style="width: 245px;" id="regex" name="regex" value="(?<=稿源[:：]).*"/>
					</td>
				</tr>
			
			</table>
			<br/><br/><br/><br/><br/><br/>
			
		</div>
		
	</body>
</html>

